<?php
include_once 'app/until/GetData.php';

class staticPageEdit extends GetData{

	public $daten;
	protected $User_Id;
	protected $aktionError;

	public function __construct($match){
		$this->daten = $match;		
	}

	public function getWort(RainTPL $design){
		$this->design = $design;
		$user_page_static = new Db_user_page_static();
		parent::GetData();
		
		if(isset($this->daten['StaticId'])){
			if (!$user_page_static->checkStaticAccess($this->daten['StaticId'],$this->ActivUser->id)) {
				HTTP::redirect ( BASE_URL . '/Explorer/Error/2' );
			}
		}	
		if(isset($this->daten['ModulId'])){
		    $modulCheck = new Db_modul();
			if (!$modulCheck->checkIfUserHaveAktiv($this->ActivUser->id,$this->daten['ModulId'])) {
				HTTP::redirect ( BASE_URL . '/Explorer/Error/3' );
			}
		}	    
		
		$crumb = new Crumb($design,2);
		
		$this->design->assign ('bcn', $crumb->getCrumb_Name());
		$this->design->assign ('bcrumb',$crumb->getCrumb());
		
        $this->design->assign('js', "jsStaticPageEdit");
		$this->design->assign('css', "StaticPageEdit");
		
		$navi = $user_page_static->getNavi("Webseiten","Deine Seiten");		
		$this->design->assign ('navi',$navi);
		
	
		if ($this->daten['StaticId'] && isset($this->design->post->ntouch_static_nr))
		{
		    $UserStaticPage = $user_page_static->updateStaticPage($this->daten['StaticId'],$this->ActivUser->id,$this->design->post->data);
		    
		    if($UserStaticPage){				
				HTTP::redirect ( BASE_URL . '/explorer/435' );
			}else{	 
				$this->design->assign ( 'page',$this->design->post->data);
				
				if( $cache = $this->design->cache($this->design->ln.'/User/Page/Static/error', $expire_time = 0 ) )
				{
				 	echo $cache;
				}
				else
				{
				 	$this->design->draw($this->design->ln.'/User/Page/Static/error');
				}
			}
		}elseif (isset($this->design->post->name))
		{
			$UserStaticPage = $user_page_static->insertStaticPage($this->ActivUser->id,$this->design->post->data);
					
			if($UserStaticPage){				
				HTTP::redirect ( BASE_URL . '/explorer/574' );
			}else{	 
				$this->design->assign ( 'page',$this->design->post->data);
				
				if( $cache = $this->design->cache($this->design->ln.'/User/Page/Static/error', $expire_time = 0 ) )
				{
				 	echo $cache;
				}
				else
				{
				 	$this->design->draw($this->design->ln.'/User/Page/Static/error');
				}
			}
		}elseif(isset($this->daten['StaticId']) && !isset($this->design->post->name)){
	    	$page = $user_page_static->getStaticPage($this->daten['StaticId'],$this->ActivUser->id);
	        $this->design->assign ( 'page',$page[0]);
	        
		    if( $cache = $this->design->cache($this->design->ln.'/User/Page/Static/Edit', $expire_time = 0 ) )
			{
			 	echo $cache;
			}
			else
			{
			 	$this->design->draw($this->design->ln.'/User/Page/Static/Edit');
			}
	    }elseif(isset($this->daten['ModulId'])){
	    	$page = $user_page_static->getStaticPage($this->daten['StaticId'],$this->ActivUser->id);
	        $this->design->assign ( 'page',$page[0]);
	        
		    if( $cache = $this->design->cache($this->design->ln.'/User/Page/Static/Edit', $expire_time = 0 ) )
			{
			 	echo $cache;
			}
			else
			{
			 	$this->design->draw($this->design->ln.'/User/Page/Static/Edit');
			}
	    }else{	    
    	    if( $cache = $this->design->cache($this->design->ln.'/User/Page/Static/new', $expire_time = 0 ) )
    		{
    		 	echo $cache;
    		}
    		else
    		{
    		 	$this->design->draw($this->design->ln.'/User/Page/Static/new');
    		}
	    }
	}

}
?>